package com.grass.appointment.adapter;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.androidx.p013lv.base.BaseSdk;
import com.androidx.p013lv.base.glide.GlideUtils;
import com.androidx.p013lv.base.recycler.BaseRecyclerAdapter;
import com.androidx.p013lv.base.recycler.BaseRecyclerHolder;
import com.androidx.p013lv.base.utils.ButtonUtil;
import com.androidx.p013lv.base.utils.SpUtils;
import com.androidx.p013lv.base.utils.TimeUtils;
import com.androidx.p013lv.base.utils.UiUtils;
import com.androidx.p013lv.base.view.CircleImageView;
import com.grass.appointment.C2694R;
import com.grass.appointment.bean.CommentBean;
import com.grass.appointment.comment.CommentHttpUtils;
import com.grass.appointment.comment.CommentVerticalLayout;
import com.like.LikeButton;
import com.like.OnLikeListener;
import java.util.ArrayList;
import java.util.List;

public class CommentAdapter extends BaseRecyclerAdapter<CommentBean, Holder> {
    private String imgDomain = "";
    private boolean isItemRefresh;
    private CommentVerticalLayout.OnTwoClickListener onTwoClickListener;
    private int userId;

    public void setItemRefresh(boolean z) {
        this.isItemRefresh = z;
    }

    public void setOnTwoClickListener(CommentVerticalLayout.OnTwoClickListener onTwoClickListener2) {
        this.onTwoClickListener = onTwoClickListener2;
    }

    public void setImgDomain(String str) {
        if (!TextUtils.isEmpty(str) && TextUtils.isEmpty(this.imgDomain)) {
            this.imgDomain = str;
        }
    }

    public void setUserId(int i) {
        this.userId = i;
    }

    public void MyHolder(Holder holder, int i) {
        holder.setData((CommentBean) getDataInPosition(i));
    }

    @Override // androidx.recyclerview.widget.RecyclerView.Adapter
    public Holder onCreateViewHolder(ViewGroup viewGroup, int i) {
        return new Holder(LayoutInflater.from(viewGroup.getContext()).inflate(C2694R.C2699layout.comment_item, viewGroup, false));
    }

    /* access modifiers changed from: package-private */
    public class Holder extends BaseRecyclerHolder {
        LikeButton bt_isLike;
        LinearLayout expansion_btn;
        TextView expansion_num_txt;
        CircleImageView imageView;
        ImageView iv_vip;
        CommentVerticalLayout layout_comment2;
        TextView tv_author;
        TextView tv_city;
        TextView tv_content;
        TextView tv_like_num;
        TextView tv_name;
        TextView tv_time;

        private Holder(View view) {
            super(view);
            this.imageView = (CircleImageView) view.findViewById(C2694R.C2697id.img_head);
            this.layout_comment2 = (CommentVerticalLayout) view.findViewById(C2694R.C2697id.layout_comment2);
            if (CommentAdapter.this.onTwoClickListener != null) {
                this.layout_comment2.setOnTwoClickListener(CommentAdapter.this.onTwoClickListener);
            }
            this.tv_name = (TextView) view.findViewById(C2694R.C2697id.tv_name);
            this.tv_author = (TextView) view.findViewById(C2694R.C2697id.tv_author);
            this.tv_content = (TextView) view.findViewById(C2694R.C2697id.tv_content);
            this.tv_time = (TextView) view.findViewById(C2694R.C2697id.tv_time);
            this.bt_isLike = (LikeButton) view.findViewById(C2694R.C2697id.bt_isLike);
            this.tv_like_num = (TextView) view.findViewById(C2694R.C2697id.tv_like_num);
            this.expansion_btn = (LinearLayout) view.findViewById(C2694R.C2697id.expansion_btn);
            this.expansion_num_txt = (TextView) view.findViewById(C2694R.C2697id.expansion_num_txt);
            this.iv_vip = (ImageView) view.findViewById(C2694R.C2697id.iv_vip);
            this.tv_city = (TextView) view.findViewById(C2694R.C2697id.tv_city);
        }

        public void setData(final CommentBean commentBean) {
            GlideUtils.loadPicHead(CommentAdapter.this.imgDomain + commentBean.getUserLogo(), this.imageView);
            this.layout_comment2.setUserId(CommentAdapter.this.userId);
            this.layout_comment2.setParentId(commentBean.getCommentId());
            boolean z = false;
            if (CommentAdapter.this.isItemRefresh) {
                if (commentBean.getReply() != null) {
                    this.layout_comment2.setVisibility(0);
                    this.layout_comment2.addCommentsWithLimit(commentBean.getReply(), commentBean.getReply().size(), false);
                } else {
                    this.layout_comment2.setVisibility(8);
                }
            } else if (commentBean.getReply() != null) {
                this.layout_comment2.setVisibility(0);
                this.layout_comment2.addCommentsWithLimit(commentBean.getReply(), 1, false);
                if (commentBean.getReply().size() != 1) {
                    this.expansion_btn.setVisibility(0);
                    TextView textView = this.expansion_num_txt;
                    textView.setText(String.valueOf("展開" + commentBean.getReply().size() + "條回復"));
                    this.expansion_btn.setOnClickListener(new View.OnClickListener() {
                        /* class com.grass.appointment.adapter.CommentAdapter.Holder.View$OnClickListenerC27561 */

                        public void onClick(View view) {
                            Holder.this.expansion_btn.setVisibility(8);
                            Holder.this.layout_comment2.addCommentsWithLimit(commentBean.getReply(), commentBean.getReply().size(), false);
                        }
                    });
                }
            } else {
                this.layout_comment2.setVisibility(8);
                this.expansion_btn.setVisibility(8);
            }
            this.tv_name.setText(commentBean.getUserNickName());
            if (CommentAdapter.this.userId == commentBean.getUserId()) {
                this.tv_author.setVisibility(0);
            } else {
                this.tv_author.setVisibility(8);
            }
            this.tv_content.setText(commentBean.getContent());
            this.tv_city.setText(commentBean.getCityName() == null ? "小草星" : commentBean.getCityName());
            this.tv_time.setText(commentBean.isMyCommit() ? "剛剛" : TimeUtils.utc2Common(commentBean.getCreatedAt()));
            this.tv_like_num.setText(UiUtils.num2str(commentBean.getLikeNum()));
            final int userId = SpUtils.getInstance().getUserInfo().getUserId();
            if (commentBean.getLikeUserIds() != null) {
                z = commentBean.getLikeUserIds().contains(Integer.valueOf(userId));
            }
            if (z) {
                this.tv_like_num.setTextColor(BaseSdk.getContext().getResources().getColor(C2694R.C2695color.E24339));
            } else {
                this.tv_like_num.setTextColor(BaseSdk.getContext().getResources().getColor(C2694R.C2695color.white));
            }
            this.bt_isLike.setLiked(Boolean.valueOf(z));
            this.bt_isLike.setOnLikeListener(new OnLikeListener() {
                /* class com.grass.appointment.adapter.CommentAdapter.Holder.C27572 */

                @Override // com.like.OnLikeListener
                public void liked(LikeButton likeButton) {
                    if (ButtonUtil.isFastDoubleClick(1000)) {
                        likeButton.setLiked(false);
                        return;
                    }
                    List<Integer> likeUserIds = commentBean.getLikeUserIds();
                    if (likeUserIds == null) {
                        likeUserIds = new ArrayList<>();
                    }
                    likeUserIds.add(Integer.valueOf(userId));
                    commentBean.setLikeUserIds(likeUserIds);
                    CommentHttpUtils.commentLike(commentBean, 0);
                    CommentBean commentBean = commentBean;
                    commentBean.setLikeNum(commentBean.getLikeNum() + 1);
                    Holder.this.tv_like_num.setTextColor(BaseSdk.getContext().getResources().getColor(C2694R.C2695color.E24339));
                    Holder.this.tv_like_num.setText(UiUtils.num2str(commentBean.getLikeNum()));
                }

                @Override // com.like.OnLikeListener
                public void unLiked(LikeButton likeButton) {
                    if (ButtonUtil.isFastDoubleClick(1000)) {
                        likeButton.setLiked(true);
                        return;
                    }
                    if (commentBean.getLikeNum() >= 1) {
                        CommentBean commentBean = commentBean;
                        commentBean.setLikeNum(commentBean.getLikeNum() - 1);
                    }
                    List<Integer> likeUserIds = commentBean.getLikeUserIds();
                    if (likeUserIds != null) {
                        for (int i = 0; i < likeUserIds.size(); i++) {
                            if (userId == likeUserIds.get(i).intValue()) {
                                likeUserIds.remove(i);
                            }
                        }
                    }
                    Holder.this.tv_like_num.setTextColor(BaseSdk.getContext().getResources().getColor(C2694R.C2695color.white));
                    Holder.this.tv_like_num.setText(UiUtils.num2str(commentBean.getLikeNum()));
                    CommentHttpUtils.commentUnlike(commentBean, 0);
                }
            });
        }
    }
}
